package com.example.dao.StudentDao;

import com.example.bean.Student;
import com.example.util.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class StudentShowDaoImp implements StudentShowDao{

    @Override
    public Student getStudentShow(Student student) {
        Connection connection=null;
        PreparedStatement preparedStatement=null;
        try {
            //1.建立连接
            connection = DBUtil.getConnection();
            //2.编写SQL语句
            String sql="select * from s_user";
            //3.预处理对象
            preparedStatement = connection.prepareStatement(sql);
            //4.获取结果集
            ResultSet resultSet = preparedStatement.executeQuery();
            while(resultSet.next()){
                //5.获取信息并且设置信息
                String sname = resultSet.getString("sname");
                student.setSname(sname);
                String ssex = resultSet.getString("ssex");
                student.setSsex(ssex);
                String sage = resultSet.getString("sage");
                student.setSage(sage);
                String semail = resultSet.getString("semail");
                student.setSemail(semail);
                String stext = resultSet.getString("stext");
                student.setStext(stext);


                System.out.println("姓名:"+student.getSname());
                System.out.println("性别:"+student.getSsex());
                System.out.println("出生日期:"+student.getSage());
                System.out.println("邮箱:"+student.getSemail());
                System.out.println("备注:"+student.getStext());

            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            //5.释放相关的资源
            try {
                DBUtil.closeResource(connection,preparedStatement);
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        return null; //表示查询结束
    }
}
